/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javalens.gui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javalens.util.Util;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author vermaak
 */
public class CurveInputPanel extends JPanel implements ActionListener {

    private JLabel startDayLabel = new JLabel("start day");
    private JLabel endDayLabel = new JLabel("end day");
    private JTextField startDayField = new JTextField("-20");
    private JTextField endDayField = new JTextField("20");
    private JLabel nPointsLabel = new JLabel("n points");
    private JTextField nPointsField = new JTextField("200");
    private JButton button = new JButton("Set Curve Params");
    private CurveInputData data;

    public CurveInputPanel() {
        super();
        setLayout(new GridLayout(0, 2));
        add(new JLabel("Curve parameters"));
        add(new JLabel(""));
        add(startDayLabel);
        add(startDayField);
        add(endDayLabel);
        add(endDayField);
        add(nPointsLabel);
        add(nPointsField);
        add(button);
        button.addActionListener(this);
    }

    public void actionPerformed(ActionEvent arg0) {
        if (arg0.getSource() instanceof JButton) {
            data = new CurveInputData();
            data.setStartDay(Util.JTextFieldToDouble(startDayField));
            data.setEndDay(Util.JTextFieldToDouble(endDayField));
            data.setNPoints(Util.JTextFieldToInteger(nPointsField));
        }
    }

    public CurveInputData getData() {
        return data;
    }
}
